package com.auth.service.impl;

import com.auth.mapper.BsRolesMapper;
import com.auth.model.BsRoles;
import com.auth.service.BsRolesService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 角色逻辑类
 * Created by Administrator on 2017/8/21 0021.
 */
@Service
public class BsRolesServiceImpl  implements BsRolesService{
    @Autowired
    private BsRolesMapper bsRolesMapper;
    /**
     * 创建角色
     * @param bsRoles
     * @return
     */
    public int createRoles(BsRoles bsRoles) {
        if(bsRoles!=null){
            return bsRolesMapper.insert(bsRoles);
        }
        return 0;
    }

    /**
     * 修改角色
     * @param bsRoles
     * @return
     */
    public int updateRoles(BsRoles bsRoles) {
        return bsRolesMapper.updateByPrimaryKeySelective(bsRoles);
    }

    /**
     * 查看角色列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    public List<BsRoles> findAll(int pageNum, int pageSize) {
        PageHelper.offsetPage(pageNum, pageSize);
        List<BsRoles> list = bsRolesMapper.selectAll();
        return list;
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    public boolean deleteRoles(String id) {
        if(!StringUtils.isEmpty(id)){
            int i= bsRolesMapper.deleteByPrimaryKey(id);
            return i>0?true:false;
        }
        return false;
    }
}
